/* $Id: HelpAction.java,v 1.12 2007/09/07 06:51:23 gigabass Exp $
 *
 * Copyright (c) Guido Ludwig. All rights reserved.
 * Use is subject to license terms.
 */
package de.guidoludwig.af;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;

/**
 * An Action to start the help
 *
 * @author <a href="mailto:jtrade@gigabss.de">Guido Ludwig </a>
 * @version $Revision: 1.12 $
 */
public class HelpAction extends AbstractAction {

	private static final AFProperties PROPERTIES = new AFProperties(HelpAction.class);
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	private static final String TOOLTIP = "action.help.tooltip";
	private static final String ICON = "action.help.icon";
	private static final String ACTON_NAME = "action.help.name";
	private static final String ABOUT = "action.help.tab.about";
	private static final String CONFIG = "action.help.tab.config"; //$NON-NLS-1$
	private static final String RELEASE_NOTES = "action.help.tab.releaseNotes";
	private static final String HELP = "action.help.tab.help";

	public HelpAction() {
		super(PROPERTIES.getString(ACTON_NAME), PROPERTIES.getIcon(ICON));
		putValue(Action.SHORT_DESCRIPTION, PROPERTIES.getString(TOOLTIP));
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	@Override
	public void actionPerformed(ActionEvent arg0) {
		SwingUtil.finishCurrentEdit();
		AbstractDialog dialog = new HelpDialog();
		dialog.open();
	}

	private class HelpDialog extends AbstractDialog {
		/**
		 *
		 */
		private static final long serialVersionUID = 1L;
		private static final String TITLE = "help.dialog.title";

		private HelpDialog() {
			super(TITLE);
		}

		@Override
		protected JComponent buildContent() {
			JPanel panel = new JPanel(new BorderLayout());
			JTabbedPane tabbedPane = new JTabbedPane();
			tabbedPane.add(createAbout(), HelpAction.PROPERTIES.getString(ABOUT));
			tabbedPane.add(createHelp(), HelpAction.PROPERTIES.getString(HELP));
			tabbedPane.add(createConfigNotes(), HelpAction.PROPERTIES.getString(CONFIG));
			tabbedPane.add(createReleaseNotes(), HelpAction.PROPERTIES.getString(RELEASE_NOTES));
			tabbedPane.add(createLog(), "Log");
			tabbedPane.setPreferredSize(new Dimension(400, 300));
			panel.add(tabbedPane, BorderLayout.CENTER);
			panel.add(buildButtonBarWithOK(), BorderLayout.SOUTH);
			return panel;
		}

		private Component createAbout() {
			JTextArea ta = new JTextArea(SwingUtil.loadResource("about.txt"));
			ta.setEditable(false);
			return new JScrollPane(ta);
		}

		private Component createReleaseNotes() {
			JTextArea ta = new JTextArea(SwingUtil
					.loadResource("release_notes.txt"));
			ta.setEditable(false);
			return new JScrollPane(ta);
		}

		private Component createHelp() {
			JTextArea ta = new JTextArea(SwingUtil.loadResource("help.txt"));
			ta.setEditable(false);
			return new JScrollPane(ta);
		}

		private Component createConfigNotes() {
			JTextArea ta = new JTextArea(SwingUtil
					.loadResource("configuration.txt")
					+ SwingUtil.loadResource("jtrade.properties"));
			ta.setEditable(false);
			return new JScrollPane(ta);
		}

		private Component createLog() {
			JTextArea ta = new JTextArea("FIXME : log messages here !");
			ta.setEditable(false);
			return new JScrollPane(ta);
		}
	}
}